;=================================================
;
; common lisp program
;
; solves symbolic differentiation equations
;
;=================================================

(load "../cl_adapter.lsp")

;=================================================
; provide differentiation routines to the
; given function
(defun dif (aF aX)
 (cond
  ((eq aF aX) 1)
  ((atom aF) 0)
  ((eq (car aF) '+)(list '+ (dif (cadr aF) aX) (dif (caddr aF) aX)))
  (T aF) ; function can not be differentiated
  )
 ) ; dif

;=================================================
;

;=================================================
; simplification routine
(defun simp (aList)

 ; simp 3
 (defun simp3 (aList)
  (setq A (cadr aList))
  (setq B (caddr aList))

  (if (eq (car aList) '+)
   (if (and (numberp A) (numberp B)) (+ A B)) ; + NUM NUM
   aList ; list can not be simplified
   )
 ) ; simp3

 ; common simplification routine
 (cond
  ((= 3 (length aList)) (simp3 aList))
  (T aList)
  )
 ) ; simp

;=================================================
; dump list
(defun dumpdff (aText aList)
 (print aText)
 (format t "~S~%" aList)
 ) ; dump


;=================================================
; defines entry function to the console application
(defun main ()

 ; show prompt
 (print "in main")

 ; test
 (setq fun (list '+ 'x 1) )
 (setq res (dif fun 'x))
 ;(dump "dif = " res )
 ;(dump "simp = " (simp res))
 ;(dump "a = " (atoms al))
 ;(dump "list = " al)
 ;(print "ap = " (append al t))



 ; stop execution
 (exit)
 ) ; main

(main)

